﻿using Zero;

/// <summary>
/// 元素反应：蒸发
/// </summary>
public class ElementVaporize : IElementReaction
{
    private readonly IElementHolder _holder;

    public ElementVaporize(IElementHolder holder)
    {
        _holder = holder;
    }

    public void Reaction(TriggerElementData triggerElementData)
    {
        if (triggerElementData.ElementType == ElementType.Water)
        {
            var fireAura = _holder.GetGeneralElementAura(ElementType.Fire);
            if (fireAura.Gauge > 0f)
            {
                var cost = triggerElementData.Gauge * 2f;
                triggerElementData.Gauge -= fireAura.Gauge * 0.5f;
                fireAura.UseGauge(cost);
                triggerElementData.DamageBoosters.Add(new ElementDamageBooster("蒸发", 2f));
                triggerElementData.IsTriggered = true;
                ServiceLocator.Get<IWorldNumberService>()
                    .CreateElementReaction(_holder.Owner.transform.position, "蒸发");
                return;
            }
        }

        if (triggerElementData.ElementType == ElementType.Fire)
        {
            var waterAura = _holder.GetGeneralElementAura(ElementType.Water);
            if (waterAura.Gauge > 0f)
            {
                var cost = triggerElementData.Gauge * 0.5f;
                triggerElementData.Gauge -= waterAura.Gauge * 2f;
                waterAura.UseGauge(cost);
                triggerElementData.DamageBoosters.Add(new ElementDamageBooster("蒸发", 1.5f));
                triggerElementData.IsTriggered = true;
                ServiceLocator.Get<IWorldNumberService>()
                    .CreateElementReaction(_holder.Owner.transform.position, "蒸发");
            }
        }
    }
}